﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace H2.NET.Web.Workflow.DwzCode
{
    public class ActionResult
    {
        #region 消息处理

        /// <summary>
        /// 返回一个成功信息Json，以便传过客户端使用。
        /// </summary>
        /// <param name="rel">ajax局部刷新时实用，需要刷新的容器ID</param>
        /// <returns></returns>

        public string SuccessMsgByRel(string rel)
        {

            return "{\"statusCode\":\"200\",\"message\":\"提交成功\",\"navTabId\":\"\",\"rel\":\"" + rel + "\",\"callbackType\":\"\",\"forwardUrl\":\"\"}";


        }

        /// <summary>
        /// 返回一个成功信息Json，以便传过客户端使用。
        /// </summary>
        /// <param name="message">显示成功信息内容</param>
        /// <param name="navTabId">提交成功后要刷新的Tab id</param>
        /// <param name="callbackType">提交成功后的操作, closeCurrent或forward</param>
        /// <param name="forwardUrl">callbackType是forward时使用</param>
        /// <returns>Json</returns>
        public string SuccessMsg(string message, string navTabId, string callbackType, string forwardUrl)
        {
            string str = "";
            str += "{\"statusCode\":\"200\""
                  + ",\"message\":\"" + message + "\""
                  + ",\"navTabId\":\"" + navTabId + "\""
                  + ",\"callbackType\":\"" + callbackType + "\""
                  + ",\"forwardUrl\":\"" + forwardUrl + "\"}";
            return str;
        }

        /// <summary>
        /// 返回一个失败信息Json，以便传过客户端使用。
        /// </summary>
        /// <param name="message">显示失败信息内容</param>
        /// <param name="navTabId">操作失败后要刷新的Tab id</param>
        /// <param name="callbackType">操作失败后的操作, closeCurrent或forward</param>
        /// <param name="forwardUrl">callbackType是forward时使用</param>
        /// <returns>Json</returns>
        public string ErrorMsg(string message, string navTabId, string callbackType, string forwardUrl)
        {

            string str = "";
            str += "{\"statusCode\":\"300\""
                   + ",\"message\":\"" + message + "\""
                   + ",\"navTabId\":\"" + navTabId + "\""
                   + ",\"callbackType\":\"" + callbackType + "\""
                   + ",\"forwardUrl\":\"" + forwardUrl + "\"}";
            return str;


        }


        public string ErrorMsg(string message, string navTabId)
        {
            return ErrorMsg(message, navTabId, "", "");
        }


        public string SuccessMsg(string navTabId)
        {
            return SuccessMsg("提交成功", navTabId, "closeCurrent", "");
        }

        public string SuccessMsg(string navTabId, string strMsg, bool showMsg)
        {
            if (!showMsg)
            {
                strMsg = "提交成功";
            }
            return SuccessMsg(strMsg, navTabId, "closeCurrent", "");
        }

        public string SuccessMsg()
        {
            return SuccessMsg("提交成功", "", "", "");
        }


        public string SuccessMsg(string navTabId, string callbackType)
        {
            return SuccessMsg("提交成功", navTabId, callbackType, "");
        }


        public string SuccessMsg(string navTabId, string callbackType, string forword)
        {
            return SuccessMsg("提交成功", navTabId, callbackType, forword);
        }

        #endregion
    }
}